package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.LocatorInfo;
import com.ruoyi.mes.service.ILocatorInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库位信息Controller
 *
 * @author LongAndHao
 * @date 2023-09-27
 */
@RestController
@RequestMapping("/mes/locator")
public class LocatorInfoController extends BaseController
{
    @Autowired
    private ILocatorInfoService locatorInfoService;

    /**
     * 查询库位信息列表
     */
    @PreAuthorize("@ss.hasPermi('mes:locator:list')")
    @GetMapping("/list")
    public TableDataInfo list(LocatorInfo locatorInfo)
    {
        startPage();
        List<LocatorInfo> list = locatorInfoService.selectLocatorInfoList(locatorInfo);
        return getDataTable(list);
    }

    /**
     * 导出库位信息列表
     */
    @PreAuthorize("@ss.hasPermi('mes:locator:export')")
    @Log(title = "库位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LocatorInfo locatorInfo)
    {
        List<LocatorInfo> list = locatorInfoService.selectLocatorInfoList(locatorInfo);
        ExcelUtil<LocatorInfo> util = new ExcelUtil<LocatorInfo>(LocatorInfo.class);
        util.exportExcel(response, list, "库位信息数据");
    }

    /**
     * 获取库位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:locator:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(locatorInfoService.selectLocatorInfoById(id));
    }

    /**
     * 新增库位信息
     */
    @PreAuthorize("@ss.hasPermi('mes:locator:add')")
    @Log(title = "库位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LocatorInfo locatorInfo)
    {
        return locatorInfoService.insertLocatorInfo(locatorInfo);
    }

    /**
     * 修改库位信息
     */
    @PreAuthorize("@ss.hasPermi('mes:locator:edit')")
    @Log(title = "库位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LocatorInfo locatorInfo)
    {
        return toAjax(locatorInfoService.updateLocatorInfo(locatorInfo));
    }

    /**
     * 删除库位信息
     */
    @PreAuthorize("@ss.hasPermi('mes:locator:remove')")
    @Log(title = "库位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return locatorInfoService.deleteLocatorInfoByIds(ids);
    }


    //**********************************
    /**
     * 查 - 库位
     * @param houId 库房id
     * @return
     */
    @PostMapping("/getLocatorByHouId")
    public AjaxResult getLocatorByHouId(@RequestParam Long houId){
        return locatorInfoService.getLocatorByHouId(houId);
    }
}
